//
//  WeiboSpaceAppDelegate.m
//  WeiboSpace
//
//  Created by  linan4 on 12-3-3.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "WeiboSpaceAppDelegate.h"
#import "HomeMessageController.h"
#import "MetionsMessageController.h"
#import "SNNavigationController.h"
@implementation WeiboSpaceAppDelegate

@synthesize window;
@synthesize tabBarController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
	
	//配置TabBar
	[self configTabBarControllers];
	//[self.window addSubview:self.tabBarController.view];
	
    [self.window makeKeyAndVisible];
    return YES;
}

#pragma mark Instance Funtions
//创建 UINavigationController
- (UINavigationController *)createNavController:(Class)cntrloller nibName:(NSString*)nibName 
																 tabIconName:(NSString*)iconName
																 tabTitle:(NSString*)tabTitle
{

	UIViewController* viewController = [[cntrloller alloc] initWithNibName:nibName bundle:nil];
	viewController.tabBarItem.image = [UIImage imageNamed:iconName];
	viewController.title = tabTitle; 
	
	UINavigationController *theNavigationController = [[[SNNavigationController alloc] initWithRootViewController:viewController]autorelease];
    
    //UIImage *barImage = [UIImage imageNamed:@"navgationbar.png"];
    
    //[theNavigationController.navigationBar setBackgroundImage:barImage forBarMetrics:UIBarMetricsDefault];
	[viewController release];
    
    
	
	return theNavigationController;
}

////配置主页显示的那些UITabBar
//-(void)configTabBarControllers
//{
//	NSMutableArray * array = [[NSMutableArray alloc] init];
//	
//	UINavigationController * navController = nil;
//	
//	//Home
//	navController = [self createNavController: [HomeMessageController class] nibName:nil tabIconName:@"" tabTitle:@"TimeLine"];
//	[array addObject:navController];
//	
//	//Metions
//	navController = [self createNavController: [MetionsMessageController class] nibName:nil tabIconName:@"" tabTitle:@"Metions"];
//	[array addObject:navController];
//	
//	//其它暂时未实现
//	navController = [self createNavController: [UIViewController class] nibName:nil tabIconName:@"" tabTitle:@"Message"];
//	[array addObject:navController];
//	
//	navController = [self createNavController: [UIViewController class] nibName:nil tabIconName:@"" tabTitle:@"Setting"];
//	[array addObject:navController];
//	
//	tabBarController.viewControllers = array;
//	//[tabBarController setHidesBottomBarWhenPushed:YES];
//	[array release];
//}

-(void)configTabBarControllers
{
    tabBarController = [[WSTabBarController alloc]init];
    NSMutableArray * array = [[NSMutableArray alloc] init];
    UINavigationController *controller = [self createNavController: [HomeMessageController class] nibName:nil tabIconName:@"" tabTitle:nil];
    
    //设置NavigationBar的背景图和颜色
    //UIImage *barImage = [UIImage imageNamed:@"navgationbar.png"];
    //[controller.navigationBar setBackgroundImage:barImage forBarMetrics:UIBarMetricsDefault];
    //[controller.navigationBar setBackgroundColor:[UIColor redColor]];
    [array addObject:controller];
    
    controller = [self createNavController: [MetionsMessageController class] nibName:nil tabIconName:@"" tabTitle:nil];
    
    [array addObject:controller];
    
    controller = [self createNavController: [UIViewController class] nibName:nil tabIconName:@"" tabTitle:nil];
    [array addObject:controller];
    
    controller = [self createNavController: [UIViewController class] nibName:nil tabIconName:@"" tabTitle:nil];
    [array addObject:controller];
    
    tabBarController.viewControllers = array;
    
    [self.window addSubview:tabBarController.view];
    [tabBarController release],tabBarController = nil;
    [array release];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    /*
     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
     */
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    /*
     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
     */
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}


- (void)applicationWillTerminate:(UIApplication *)application {
    /*
     Called when the application is about to terminate.
     See also applicationDidEnterBackground:.
     */
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    /*
     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
     */
}


- (void)dealloc {
	[tabBarController release];
    [window release];
    [super dealloc];
}


@end
